package com.hzit.manager.config;

import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {
 
    @Value("${spring.datasource.driver-class-name}")
    private String driverClassName;
 
    @Value("${spring.datasource.url}")
    private String url;
 
    @Value("${spring.datasource.name}")
    private String name;
 
    @Value("${spring.datasource.username}")
    private String username;
 
    @Value("${spring.datasource.password}")
    private String password;
 
    @Bean
    @Primary
    public DataSource dataSource(){
 
        DruidDataSource druidDataSource=new DruidDataSource();
        druidDataSource.setDriverClassName(driverClassName);
        druidDataSource.setUrl(url);
        druidDataSource.setName(name);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
 
        DataSourceProxy dataSourceProxy=new DataSourceProxy(druidDataSource);
        System.out.println("dataSourceProxy(user):" + dataSourceProxy);
        return dataSourceProxy;
    }
}